<template>
  <div ref="chart" class="chart"></div>
</template>

<script>
import * as echarts from "echarts";
import { mapState } from "vuex";
export default {
  data() {
    return {
      homeChart:null
    };
  },
  computed: {
    ...mapState("Home",["option"])
  },
  watch:{
    option:{
      handler(newVal,oldVal){
        this.$nextTick(()=>{
          this.homeChart.setOption(newVal)
        })
      },
      immediate:true,
      deep:true
    }
  },
  mounted() {
    this.homeChart = echarts.init(this.$refs.chart);
  }
};
</script>

<style scoped>
.chart {
  width: 100%;
  height: 300px;
}
</style>